<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
  	<script th:src="'/quickJs/scripts/easyui/1.5.2/plugins/datagrid-detailview.js'"></script>
    <title>查看服务</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <style>
    	.title{
			height:35px;
			line-height:35px;
			font-size:15px;
			background:#F7F9FB;
			margin-left:0px;
			padding-left:8px;
			font-weight:bold;
		}
		.padding-left{
			padding-left:20px;
			font-size:16px;
/* 			background:#ffe48d; */
			cursor:pointer;
		}
		.panel-tool-collapse{
			display: block;
		    width: 17px;
		    height: 16px;
		    position: absolute;
		    top: 15px;
		    left: 106px;
		}
		.tabs-wrap>.tabs>li>a{
			border-left:1px solid #438EB9!important;
			border-right:1px solid #438EB9!important;
			border-top:1px solid #438EB9!important;
		}
		/*浮雕字体css*/
		.fdztCss{
			text-shadow: 1px 1px 0 rgba(255, 255, 255, .7);
			color:#ccc;
		}
    </style>
	<script>
		var qyData = StoreCache.getCache("qyData");
		$(function(){
			initView();
			initData();
		})
		function initView(){
			$('#tabs').tabs({
				border: true,
			    fit: true,
			    tabWidth: "150",
				onSelect: function(title,index){
					var nowSelectTab = $(this).tabs('getTab',index); //获取到当前激活的tab
					var tableId = nowSelectTab.find("table").attr("id");
					if(!StringUtils.isEmpty(tableId)){
						viewMethod[tableId](); //初始化table
					}
				}
			})
			//返回按钮
			var backUrl = StoreCache.removeCache("backUrl");
			$("#backBtn").click(function(){
				$.QuickUrlUtils.redirectUrl(backUrl);
			})
			//签约历史
			$("#history").click(function(){
				StoreCache.setCache("qyData",qyData);
				StoreCache.setCache("backUrl",backUrl);
				$.QuickUrlUtils.redirectUrl("historyQyfw.html");
			})
		}
		
		function initData(){
			//查询居民基本信息
			QYXXID = qyData.QYXXID;
			$.QuickRemote.AjaxJson(contextRoot + "wdqyhz/queryJmxx", queryJmjbxxBack, {QYXXID: QYXXID});
			//查询标签页统计数目
			$.QuickRemote.AjaxJson(contextRoot + "wdqyhz/queryCountInCkfw", function(result){
				$("#YWCFWCS").html(result.YWCFWCS || 0);
				$("#DWCFWCS").html(result.DWCFWCS || 0);
				$("#DFPFWCS").html(result.DFPFWCS || 0);
			}, {QYXXID: QYXXID});
		}
		
		/** 查询居民基本信息回调  */
		function queryJmjbxxBack(result){
			result.YLJGMC = parent.userInfo.YLJGMC;
			result.QYYXQ = cutDate_YYYYMMDD(result.SXSJ) + ' 到 '+ cutDate_YYYYMMDD(result.JSSJ);
			result.CSRQ = cutDate_YYYYMMDD(result.CSRQ);
			
			for(var key in result){
				$("#"+key).html(result[key]);
			}
			$("#jtcyTable").data("JMXXID", result.JMXXID);
			viewMethod.jtcyTable();
		}
		
		/** 时间截取  */
		function cutDate_YYYYMMDD(date){
			if(!StringUtils.isEmpty(date)){
				date = date.substring(0,10);
			}
			return date;
		}
		
		/** 初始化视图的方法  */
		var viewMethod = {
				jtcyTable: function(){
					//已完成服务（父子表）
					//1.父表属性
					$("#jtcyTable").datagrid({
						idField : "JMXXID",
						striped : true,
						clickToSelect: true,
						fitColumns: true,
						fit:true,
						scrollbarSize:12,
						singleSelect:true,
						columns : [[
								{field : "XM",title : "家庭成员",width:30, align:'center'},
								{field : "CYGXMC",title : "与签约人关系",width:60, align:'center'},
								{field : "QYTDMC",title : "签约团队",width:60, align:'center',formatter:function(value){
									return value || '未签约';
								}},
								{field : "QYFWB",title : "签约服务包",width:120, align:'center',formatter:function(value){
									return value || '未签约';
								}},
						]],
						method : "post",
						url: contextRoot + 'wdqyhz/queryJtcyQyxxByJmxxid.service',
						onBeforeLoad : function(params) {
							var JMXXID = $("#jtcyTable").data("JMXXID");
							if(!StringUtils.isEmpty(JMXXID)){
								params.JMXXID = JMXXID;
							}else{
								return false;
							}
						},
						onLoadSuccess: function(data){
// 		 					alert(JSON.stringify(data))
							$("#jtcyNum").html(data.rows.length)
		 				},
		 				//2.子表属性
		 				view: detailview,
		 			    detailFormatter:function(index,row){
		 			        return '<div style="padding-bottom:5px;"><table class="sonTable"></table></div>';
		 			    },
		 			    onExpandRow: function(index,row){
		 			    	if(StringUtils.isEmpty(row.QYTDMC)){
		 			    		return;
		 			    	}
		 			        var sonTable = $(this).datagrid('getRowDetail',index).find('table.sonTable');
		 			        sonTable.datagrid({
		 			            url: contextRoot + 'wdqyhz/queryFwxxByQyxxids.service',
		 			            fitColumns:true,
		 			            singleSelect:true,
		 			            rownumbers:true,
		 			            height:'auto',
		 			            border: false,
		 			            columns:[[
		 			                {field:'FWMC',title:'服务项名称',width:100},
		 			                {field:'FWNR',title:'服务内容',width:100},
		 			                {field:'YFPCS',title:'已提供服务次数',width:100,formatter: function(value){
		 			                	return value || 0;
		 			                }},
		 			                {field:'syfwcs',title:'剩余服务次数',width:100,formatter: function(value,row){
// 		 			                	alert(parseInt(row.FWPC || 0))
// 		 			                	alert(parseInt(row.YFPCS || 0))
		 			            	   return parseInt(row.FWPC || 0)-parseInt(row.YFPCS || 0) || '无限';
		 			                }}
		 			            ]],
		 			            pagination: true,
		 			            onResize:function(){
		 			                $('#jtcyTable').datagrid('fixDetailRowHeight',index);
		 			            },
		 			            onLoadSuccess:function(){
	 			                    $('#jtcyTable').datagrid('fixDetailRowHeight',index);
		 			            },
		 			            onBeforeLoad: function(params){
		 			            	if(row.QYXXID){
			 			            	params.QYXXIDS = row.QYXXID;
		 			            	}else{
		 			            		return false;
		 			            	}
		 			            }
		 			        });
		 			        $('#jtcyTable').datagrid('fixDetailRowHeight',index);
		 			    }
						
					});
				},
				ywcfwTable: function(){
					//已完成服务
					$("#ywcfwTable").datagrid({
						idField : "FWID",
						striped : true,
						clickToSelect: true,
						fitColumns: true,
						fit:true,
						scrollbarSize:0,
						columns : [[
								{field : "SJFWSJ",title : "服务时间",width:30, align:'center',formatter:function(value){
						    		if(!StringUtils.isEmpty(value)){
						    		    return value.substring(	0,10);
									}
								}},
								{field : "FWMC",title : "服务项名称",width:60, align:'center'},
								{field : "FWNR",title : "服务项内容",width:60, align:'center',formatter:function(value){
                                    return '<span title="'+ value +'">'+ value + '</span>'
                                }},
								{field : "FWBMC",title : "服务包名称",width:60, align:'center',formatter:function(value){
									if(StringUtils.isEmpty(value)){
										return '<span class="fdztCss">医保服务项</span>';
									}else{
										return '<span title="'+ value +'">'+ value + '</span>'
									}
								}},
								{field : "FWRY",title : "服务人员",width:40, align:'center'},
								{field : "BZ",title : "备注",width:140, align:'center'},
						]],
						pagination : true,
						pageList: [10, 20, 50, 100, 200],
						method : "post",
						url: contextRoot + 'wdqyhz/queryYfpfwxByPage.service',
						onBeforeLoad : function(params) {
							if(qyData){
								params.QYXXID = qyData.QYXXID;
								params.FWZT= 1; //查询已完成
							}else{
								return false;
							}
						},
						onLoadSuccess: function(data){
// 		 					alert(JSON.stringify(data))
		 				}
					});
				},
				dwcfwTable: function(){
					//待完成服务
					$("#dwcfwTable").datagrid({
						idField : "FWID",
						striped : true,
						clickToSelect: true,
						fitColumns: true,
						fit:true,
						scrollbarSize:0,
						columns : [[
								{field : "YQFWSJ",title : "预期服务时间",width:30, align:'center',formatter:function(value){
                                    if(!StringUtils.isEmpty(value)){
                                        return value.substring(	0,10);
                                    }
                                }},
								{field : "FWMC",title : "服务项名称",width:60, align:'center',formatter:function(value){
									return '<span title="'+ value +'">'+ value + '</span>'
                                }},
								{field : "FWNR",title : "服务项内容",width:60, align:'center'},
								{field : "FWBMC",title : "服务包名称",width:60, align:'center',formatter:function(value){
                                    if(StringUtils.isEmpty(value)){
                                        return '<span class="fdztCss">医保服务项</span>';
                                    }else{
                                        return '<span title="'+ value +'">'+ value + '</span>'
                                    }
                                }},
								{field : "FWRY",title : "服务人员",width:40, align:'center'},
								{field : "BZ",title : "备注",width:140, align:'center'},
						]],
						pagination : true,
						pageList: [10, 20, 50, 100, 200],
						method : "post",
						url: contextRoot + 'wdqyhz/queryYfpfwxByPage.service',
						onBeforeLoad : function(params) {
							if(qyData){
								params.QYXXID = qyData.QYXXID;
								params.FWZT= 0; //查询待完成
							}else{
								return false;
							}
						},
						onLoadSuccess: function(data){
// 		 					alert(JSON.stringify(data))
		 				}
					});
				},
				dfpfwTable: function(){
					//待分配服务
					$("#dfpfwTable").datagrid({
						idField : "QYXXID",
						striped : true,
						clickToSelect: true,
						fitColumns: true,
						fit:true,
						scrollbarSize:0,
						singleSelect:true,
						columns : [[
								{field : "FWMC",title : "服务项名称",width:30, align:'center'},
								{field : "FWNR",title : "服务项内容",width:60, align:'center',formatter:function(value){
									return '<span title="'+ value +'">'+ value + '</span>'
                                }},
								{field : "FWBMC",title : "服务包名称",width:60, align:'center',formatter:function(value){
                                    if(StringUtils.isEmpty(value)){
                                        return '<span class="fdztCss">医保服务项</span>';
                                    }else{
                                        return '<span title="'+ value +'">'+ value + '</span>'
                                    }
                                }},
								{field : "FWPC",title : "服务频次",width:60, align:'center'},
								{field : "DFPFW",title : "待分配服务(次数)",width:60, align:'center',formatter: function(value,row){
									if(row.FWPC=='无限'){
										return '无限';
									}else{
                                        return parseInt(row.FWPC || 0)-parseInt(row.YFPCS || 0);
									}
								}},
						]],
						pagination : true,
						pageList: [10, 20, 50, 100, 200],
						method : "post",
						url: contextRoot + 'wdqyhz/queryFwxxByQyxxids.service',
						onBeforeLoad : function(params) {
							if(qyData){
								params.QYXXIDS = qyData.QYXXID;
							}else{
								return false;
							}
						},
						onLoadSuccess: function(data){
// 		 					alert(JSON.stringify(data))
		 				}
					});
				},
		}
		
	</script>
  </head>
  
  <body class="easyui-layout" border="false" fit="true">
    <div region="north"  border="false" style="height:215px;background:#f9f9f9;padding-bottom:5px;overflow:hidden">
    			<div class="title" style="border-bottom:1px solid #ccc;margin-bottom:5px;">
    				<span>签约信息</span>
    			</div>
				<table class="form-table">
					<tr>
						<td class="td-text">居民姓名</td>
						<td id="XM"></td>
						<td class="td-text">证件号码</td>
						<td id="ZJHM"></td>
						<td class="td-text">手机号码</td>
						<td id="SJHM"></td>
					</tr>
					<tr>
						<td class="td-text">出生日期</td>
						<td id="CSRQ"></td>
						<td class="td-text">性别</td>
						<td id="XBMC"></td>
						<td class="td-text">就诊卡号</td>
						<td id="JZKH"></td>
					</tr>
					<tr>
						<td class="td-text">家庭地址</td>
						<td id="JTZZ"></td>
						<td class="td-text">人群分类</td>
						<td id="RQFL"></td>
						<td class="td-text">签约机构</td>
						<td id="YLJGMC"></td>
					</tr>
					<tr>
						<td class="td-text">签约团队</td>
						<td id="QYTDMC"></td>
						<td class="td-text">签约服务包</td>
						<td id="QYFWB"></td>
						<td class="td-text">签约有效期</td>
						<td id="QYYXQ"></td>
					</tr>
				</table>
			
	</div>
	<div region="center" border="false">
		<div id="tabs" class="easyui-tabs" fit="true" border="false" style="position:relative">
			<button type="button" style="position:absolute;right: 40px;z-index:999" id="history">历史服务详情</button>
			<div title="家庭成员(<span style='color:red' id='jtcyNum'>0</span>)"  border="false">
				<table id="jtcyTable" border="false"></table>
			</div>
			<div title="已完成服务(<span style='color:red' id='YWCFWCS'>0</span>)" border="false">
				<table id="ywcfwTable" border="false"></table>
			</div>
			<div title="待完成服务(<span style='color:red' id='DWCFWCS'>0</span>)" border="false">
				<table id="dwcfwTable" border="false"></table>
			</div>
			<div title="待分配服务(<span style='color:red' id='DFPFWCS'>0</span>)" border="false">
				<table id="dfpfwTable" border="false"></table>
			</div>
		</div>
	</div>
	<div region="south" style="height:40px;line-height:40px;text-align:center;overflow:hidden;">
		<button type="button" id="backBtn">返回</button>
	</div>
  </body>
</html>
